package NumSort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class NumSortReduce extends Reducer<NumSortBean, NumSortBean, LongWritable, LongWritable> {
    //reduce方法的调用是相同key的value组成一个集合调用一次
    int num_int = 0;
    LongWritable one_IntWritable ;
    LongWritable intWritable ;

    protected void reduce(NumSortBean key, Iterable<NumSortBean> values, Context context) throws IOException, InterruptedException {
        //为了避免前面compareTo方法合并，遍历values获取每个key（bean对象）
        //遍历value同时，key也会随着遍历。
        for (NumSortBean value : values) {
            num_int = num_int + 1;
            one_IntWritable = new LongWritable(num_int);
            System.out.println("Reduce ----1----方法执行了。。。key" + key.getNumxh() + "------Number。。。" + key.getNumRm());
            intWritable = new LongWritable(key.getNumxh());
            context.write(one_IntWritable,intWritable);
        }
    }
}
